import { createRouter, createWebHistory, RouteRecordRaw } from 'vue-router'

const Home = () => import('@/pages/home.vue')
const Login = () => import('@/pages/login.vue')
const Source = () => import('@/pages/source.vue')
const World = () => import('@/pages/world.vue')
const Person = () => import('@/pages/person.vue')

const routes: RouteRecordRaw[] = [
    {
        path: "/",
        name: 'index',
        component: Home,
        meta: { requiresAuth: true } // 添加表示需要验证
    },
    {
        path: "/login",
        name: 'login',
        component: Login,
    },
    {
        path: "/source",
        name: 'source',
        component: Source,
    },
    {
        path: "/world",
        name: 'world',
        component: World,
    },
    {
        path: "/person",
        name: 'person',
        component: Person,
    },
]

const router = createRouter({
    // base url 基础路径
    history: createWebHistory('/vite/'),
    routes,
})

// router.beforeEach((to, from, next) => {
//     if (to.meta.requiresAuth) {
//         if (!localStorage.token) {
//             next({ path: '/login', })
//         } else {
//             next()
//         }
//     } else {
//         next()
//     }

// })

export default router
